package com.hrs.util;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

/**
 * @author 摆渡人
 * @description
 * @date 2022/12/6 14:24
 */
@Component
public class RedisIdWorker {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     *
     * @param keyPrefix 业务前缀
     * @return 全局唯一id
     */
    public long nextId(String keyPrefix,Integer year){
        //自增长
        long count = stringRedisTemplate.opsForValue().increment("icr:" + keyPrefix + ":" + year);

        //3.拼接并返回
        return count % 100;
    }
}
